<?php
namespace app\system\controller;

use think\Request;

class BaseController extends \think\Controller
{
    /**
     * 初始化
     * BaseController constructor.
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        parent::__construct($request);
        if ($this->getUid() <= 0) {
            switch ($this->getUtype()){
                case 'system':
                    $url = url('Public/sysLogin');
                    break;
                case 'site':
                    $url = url('Public/siteLogin');
                    break;
                case 'operator':
                    $url = url('Public/siteOperatorLogin');
                    break;
                default:
                    $url = url('Public/sysLogin');
                    break;
            }
            $this->error('请登录后再操作！',$url);
        }
    }

    /**
     * 获取用户类型
     * @return string
     */
    public function getUtype()
    {
        return str_decode(cookie('utype'));
    }

    /**
     * 获取用户UID
     * @return bool|mixed
     */
    public function getUid()
    {
        $uid = is_login($this->getUtype());
        return $uid;
    }

    /**
     * 获取站点ID
     * @return int
     */
    public function getSiteId()
    {
        return str_decode(cookie('siteId'));
    }

}